package com.data.modules.smzh.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.data.common.util.KamliClientUtil;
import com.data.modules.sm.entity.SmProject;
import com.data.modules.sm.service.ISmProjectService;
import com.data.modules.smzh.entity.*;
import com.data.modules.smzh.mapper.SmManageIntMapper;
import com.data.modules.smzh.service.IBuildingService;
import com.data.modules.smzh.service.IDevicebuildService;
import com.data.modules.smzh.service.IFacedeviceService;
import com.data.modules.smzh.service.ISmManageIntService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.*;

/**
 * @Description: 管理机初始化表
 * @Author: data-boot
 * @Date:   2023-02-13
 * @Version: V1.0
 */
@Service
public class SmManageIntServiceImpl extends ServiceImpl<SmManageIntMapper, SmManageInt> implements ISmManageIntService {


    @Autowired
    private ISmProjectService projectService;

    @Autowired
    private IDevicebuildService devicebuildService;

    @Autowired
    private IFacedeviceService facedeviceService;

    @Override
    public void pushMsg(String ids, String model, String projectNo) {
        SmProject smProject = projectService.getById(projectNo);
        String serialNo =smProject.getAppId()+smProject.getProjectNo();

        SmManageInt manageInt = this.getById(ids);
        List mapList = new ArrayList();
        mapList.add(manageInt);
        String comd = "entDoorInitNotice";

        if(ObjectUtil.equals("SMW-A10",model)){//门口机

            List<Facedevice> list = facedeviceService.lambdaQuery().eq(Facedevice::getAppId,smProject.getAppId())
                    .eq(Facedevice::getModel,model).list();

            list.stream().forEach(x->{

                KamliClientUtil.doPostpushMsgUr(x.getSerialNo(),comd,mapList);
            });
        }

        SmManageInt smPushMsg = new SmManageInt();
        smPushMsg.setId(ids);
        smPushMsg.setStatus(1);
        smPushMsg.setUpdateTime(new Date());
        this.baseMapper.updateById(smPushMsg);


    }
}
